package org.spring.blog.controller.portal;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.spring.blog.response.ResponseResult;
import org.spring.blog.response.ResponseState;
import org.spring.blog.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/portal/app")
public class AppApi {

    @Autowired
    IUserService userService;

    /**
     * 扫码下载app的接口
     *
     * @param code      二维码对应的唯一值
     * @param _request  请求体
     * @param _response 响应体
     * @return 自定义的返回对象
     */
    @ApiOperation("扫码下载app的接口")
    @ApiResponses({
            @ApiResponse(code = ResponseState.failed_code, message = ResponseState.failed_message),
            @ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message),
    })
    @GetMapping("/{code}")
    public ResponseResult downloadAppForThirdPartScan(@PathVariable String code,
                                                      HttpServletRequest _request, HttpServletResponse _response) {
        return null;
    }

    /**
     * 检查二维码的状态
     *
     * @return 自定义的返回对象
     */
    @ApiOperation("检查二维码的状态")
    @ApiResponses({
            @ApiResponse(code = ResponseState.qr_code_is_waiting_code, message = ResponseState.qr_code_is_waiting_message),
            @ApiResponse(code = ResponseState.qr_code_is_over_code, message = ResponseState.qr_code_is_over_message),
            @ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message),
    })
    @GetMapping("/qr-code-state/{_qrCode}")
    public ResponseResult checkQrCodeLoginState(@PathVariable String _qrCode) {

        return userService.checkQrCodeLoginState(_qrCode);
    }

    /**
     * 更新二维码的状态
     *
     * @return 自定义的返回对象
     */
    @ApiOperation("更新二维码的状态")
    @ApiResponses({
            @ApiResponse(code = ResponseState.user_not_login_code, message = ResponseState.user_not_login_message),
            @ApiResponse(code = ResponseState.failed_code, message = ResponseState.failed_message),
            @ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message),
    })
    @PutMapping("/qr-code-state/{_loginId}")
    public ResponseResult updateQrCodeLoginState(@PathVariable String _loginId) {

        return userService.updateQrCodeLoginState(_loginId);
    }
}
